package de.softcon.sc4retail;

import de.softcon.sc4retail.domainmodel.Stock;
import android.content.Context;
import android.content.res.TypedArray;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
    private Context myContext;

    private Integer[] myImageIds = {    		
            R.drawable.burtonbluntwide,
            R.drawable.burtonbulletwide,
            R.drawable.burtonclash,
            R.drawable.burtoncustomflying,
            R.drawable.burtonhate,
            R.drawable.burtondeucewide,
            R.drawable.burtoneasyliving
    };
    
    public ImageAdapter(Context c) {
    	this.myContext = c;
    }

    public int getCount() {
        return this.myImageIds.length;
    }

    /* Use the array-Positions as unique IDs */
    public Object getItem(int position) 
    { 
    	return position; 
    }
    
    public Object getItemInformation(int position)
    {
    	return Stock.getInstance().getSnowboards().get(position);
    }
    
    public long getItemId(int position) 
    { 
    	return position; 
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(this.myContext);

        i.setImageResource(this.myImageIds[position]);
        /* Image should be scaled as width/height are set. */
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        /* Set the Width/Height of the ImageView. */
        i.setLayoutParams(new Gallery.LayoutParams(150, 150));
        return i;
    }
    
    /** Returns the size (0.0f to 1.0f) of the views
     * depending on the 'offset' to the center. */
    public float getScale(boolean focused, int offset) {
        return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset)));
    }
}
